<template>
	<view class="items">
		<view class="food-head">
			<image :src="details.avatar" @click="previewImg(details.avatar)" mode="aspectFill">
			</image>

		</view>

		<view style="display: flex;flex-direction: column;justify-content: flex-start">
			<view style="font-weight: bold;font-size: 42upx;margin-top: 10upx;margin-left: 12upx;">
				{{details.name}}
			</view>

			<view
				style="display: flex;flex-direction: row;align-items: center;justify-content: space-between;margin-top: 12upx;margin-left: 16upx;font-size: 32upx;color: gray;">
				<view>
					工作经验{{details.experience}}年
				</view>
				<view class="price">
					价格:{{details.price}}元/小时
				</view>
			</view>
		</view>



		<!-- 菜谱简介 -->
		<view class="food-inrduc">
			<view class="inrduc-center">
				<text class="online">——</text>
				<text class="txt" style="color: #000000;">厨师简介</text>
				<text class="online">——</text>
				<text class="fuhao">▼</text>
			</view>
			<view class="content">{{details.name}}/{{details.specialty}}</view>
			
			
			
			<view class="inrduc-center" style="margin-top: 50upx;">
				<text class="online">——</text>
				<text class="txt" style="color: #000000;">预约信息</text>
				<text class="online">——</text>
				<text class="fuhao">▼</text>
			</view>
			
			<view style="display: flex;flex-direction: row;align-items: center;justify-content: space-between;margin-top: 30upx;"> 
				<u-input v-model="showDate" :type="type" :border="border" placeholder="预约时间" />
				<view style="display: flex;flex-direction: row;align-items: center;"  @click="show = true">
					<text>请选择</text>
					<image src="../../static/images/right-icon.png"  style="width: 40upx;height: 40upx;"></image>
				</view>
				
			
			</view>
			
			
			
			<u-picker mode="time" v-model="show" :params="params" @confirm="confirmTime">
			</u-picker>
			
			
		</view>






		<view style="margin-left: 50%;transform: translate(-50%);">



		</view>

		<view class="food-step">


			<!-- 底部导航 -->
			<view class="goods_nav">

				<view class="btn">
					<button @click='appointChef' class="btn-left">立即预约</button>
					<button @click='goCart' class="btn-right">我的订单</button>
				</view>
			</view>
		</view>



		

	</view>
</template>

<script>
	import {
		mapState,
		mapMutations,
		mapGetters
	} from 'vuex'
	import {
		myRequestPost
	} from '@/utils/request.js';
	import uniPopup from '@/components/uni-popup/uni-popup.vue';
	import shareBtn from '@/components/share-btn/share-btn.vue';
	import uniIcons from "@/components/uni/uni-icons/uni-icons.vue";

	import {
		cookbook_detail
	} from '@/api/ap_cookbook.js'

	import {
		user_collect
	} from '@/api/user_collect.js'

	import {
		user_join
	} from '@/api/user_cart.js'

	import {
		chef_detail,
		appointment_chef
	} from '@/api/chef.js'
	export default {
		components: {
			uniPopup,
			shareBtn,
			uniIcons
		},
		data() {
			return {
				showDate: '', //默认内容，可以是时间，也可以是提示文字
				params: { //参数配置，如果要显示时、分、秒，将对应的false改为true
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false
				},
				foodId: "",
				details: {},
				prepare: [],
				step1: [],
				len: "",
				step_length: "",
				pickerTime: false,
				count: "",
				value1: Number(new Date()),
				flag: false,
				show: false,
				title: "",
				obj: {},
				detailStorge: "",
				detailId: "",
				n: 0,
				accessory: [],
				main: [],
				canIUseShareButton: true,
				formData: {},
				sharedata: {
					type: 1,
					strShareUrl: "http://www.baidu.com",
					strShareTitle: "分享标题",
					strShareSummary: "分享总结",
					strShareImageUrl: "http://www.xuelejia.com/xljapp/h5/static/aboutUsLogo.png"
				},
				value: '',
				type: 'text',
				border: true
			}
		},
		onLoad(options) {
			this.detailId = options.id;
			this.getDetails();
		},
		// #ifdef MP-ALIPAY
		setShareButtonSwitch() {
			this.setData({
				canIUseShareButton: my.canIUse('button.open-type.share')
			})
		},
		// #endif
		onShareAppMessage(res) {
			return {
				title: "美食分享",
				path: "pages/themeDetails/themeDetails"
			}
		},

		methods: {
			confirmTime(e) {
				//可以将e在控制台打印出来看看
				this.showDate = e.year + '-' + e.month + '-' + e.day
				//将选中的日期值 赋值给 d 变量
				var d = new Date(e.year + '-' + e.month + '-' + e.day);
				var weeks = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
				//通过调用getDay()方法就能知道当前日期是星期几
				var week = d.getDay()
				this.formData.appointmentTime = e.year + '-' + e.month + '-' + e.day 
			},


			timeConfirm(e) {
				console.log(e);
				this.formData.appointmentTime = e.year + '-' + e.month + '-' + e.day;
			},

			cancel() {
				this.show = false
			},
			appointChef() {

				let params = {}
				params.chefId = this.detailId
				params.appointmentTime = this.formData.appointmentTime
				params.meals = 1
				appointment_chef(params).then(res => {
					if (res.code === '200') {
						uni.showToast({
							title: '预约成功',
							icon: 'none'
						})
						setTimeout(()=>{
							uni.navigateTo({
								url:'/pages/appointment/appointment'
							})
						},1000)
						
					}
				})
			},

			getDetails() {
				let params = {}
				params.id = this.detailId
				chef_detail(params).then(res => {
					if (res.code === '200') {
						this.details = res.data
					}
				})
			},
			//收藏保存数据
			handleflag() {
				let params = {}
				if (!this.flag) {
					params.type = 1;
				} else {
					params.type = 2
				}
				params.foodId = this.foodId
				user_collect(params).then(res => {
					if (res.code === '200') {
						if (!this.flag) {
							uni.showToast({
								title: '收藏成功'
							})
							this.flag = true
						} else {
							uni.showToast({
								title: '取消成功'
							})
							this.flag = false
						}
					}
				})
			},

			previewImg(imageUrl) {
				console.log(imageUrl)
				var images = [];
				images.push(imageUrl);
				console.log(images)
				uni.previewImage({ // 预览图片  图片路径必须是一个数组 => ["http://192.168.100.251:8970/6_1597822634094.png"]
					current: 0,
					urls: images
				});
			},
			goIndex() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			shareOn() {
				this.$refs.sharepopup.open();
			},
			buttonClick(e) {
				let params = {}
				params.type = 1;
				params.foodId = this.foodId
				user_join(params).then(res => {
					if (res.code === '200') {
						uni.showToast({
							title: '加入成功',
							icon: 'none'
						})
					}
				})

			},
			goCart() {
				uni.navigateTo({
					url: '/pages/appointment/appointment'
				})
			}

		}
	}
</script>

<style lang="scss">
	.pop-window {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		margin-top: 56upx;
	}

	.chef-title {
		color: #303133;
		text-align: center;
		font-size: 26upx;
		font-weight: bold;
	}

	.popup-info {
		position: fixed;
		width: 600upx;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		padding: 40upx;
		border-radius: 20upx;
		background-color: #fff;
		z-index: 9999;
	}

	.popup {
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		height: 100vh;
		background-color: rgba(0, 0, 0, 0.6);
		z-index: 9998;
	}


	.items {
		display: flex;
		box-sizing: border-box;
		flex-wrap: wrap;
		font-family: "楷体";

		.food-head {
			position: relative;

			image {
				width: 750rpx;
				height: 550rpx;
				background-size: cover;
			}

			.food-name {
				position: absolute;
				bottom: -80rpx;
				left: 50%;
				margin-left: -37rpx;
				padding: 10rpx;
				width: 60rpx;
				background-color: rgba($color: #fff, $alpha: 0.81);
				opacity: 0.7;
				border-radius: 30rpx;
				text-align: center;

				.name-txt {
					padding: 13rpx 12rpx;
					border: 1rpx solid #000;
					font-size: 33rpx;
					border-radius: 20rpx;
					color: #000;
					line-height: 43rpx;
				}
			}
		}

		.food-inrduc {
			width: 710rpx;
			margin-top: 100rpx;
			margin-bottom: 40rpx;
			margin-left: 20rpx;
			color: #979797;

			.content {
				margin-left: 38rpx;
				text-indent: 2em;
			}
		}

		.meterials {
			margin-left: 50rpx;
			margin-bottom: 20rpx;
		}

		.goods_nav {
			position: fixed;
			display: flex;
			bottom: 0;
			width: 100%;
			background-color: #fff;
			left: 20%;

			.tab {
				display: flex;
				padding: 0 5px;
				font-size: 12px;

				.tab_item {

					margin: 0 10px;
					margin-top: 15rpx;

					.tab-btn {
						border: 0;

						.share-btn {
							// width: 80rpx;
							height: 38rpx;
							padding: 0;
							background-color: #fff;
							line-height: 27rpx;
							font-size: 12px;
							border: none;
							outline: none;
						}

						/* #ifdef MP-ALIPAY */
						.share-btn {
							// width: 80rpx;
							height: 30rpx;
							padding: 0;
							background-color: #fff;
							line-height: 27rpx;
							font-size: 12px;
							border: none;
							outline: none;
						}

						/* #endif */
					}
				}
			}

			.btn {
				float: right;
				display: flex;
				width: 446rpx;
				height: 80rpx;
				margin: 5px 0;
				margin-right: 10px;
				overflow: hidden;

				button {
					height: 80rpx;
					line-height: 80rpx;
					font-size: 14px;

					flex: 1;
				}

				button::after {
					border: none;
				}

				.btn-left {
					border-top-left-radius: 200rpx;
					border-bottom-left-radius: 200rpx;
					background-color: #ff0000;
					color: #fff;
				}

				.btn-right {
					border-top-right-radius: 200rpx;
					border-bottom-right-radius: 200rpx;
					background-color: #ffa200;
					color: #fff;
				}
			}
		}

		.inrduc-center {
			text-align: center;
			color: orange;

			.txt {
				font-size: 35rpx;
				font-weight: 520;
				padding: 0 20rpx;
			}

			.fuhao {
				display: block;
			}

		}

		.food-ingred {
			width: 650rpx;
			height: 50rpx;
			line-height: 50rpx;
			color: #333;
			margin: 0 auto;
			border-bottom: 1px solid #ccc;

			text {
				margin-left: 130rpx;
			}

			.text-right {
				margin-right: 150rpx;
				float: right;
			}
		}

		.food-step {
			display: flex;
			box-sizing: border-box;
			flex-wrap: wrap;

			.inrduc-center {
				margin-left: 212rpx;
			}

			image {
				width: 640rpx;
				height: 600rpx;
				margin-left: 55rpx;
				background-size: cover;
			}

			.food-step-desc {
				width: 670rpx;
				margin-left: 40rpx;
				line-height: 36rpx;
				margin-bottom: 20rpx;
			}

			.steps {
				display: flex;
				box-sizing: border-box;
				margin: 10rpx 0 10rpx 50rpx;

				.desc {
					width: 580rpx;
					padding-left: 5rpx;
					letter-spacing: 2rpx;
					line-height: 40rpx;
					color: #666;
					text-indent: 1em;
				}
			}

			.food-step-main {
				width: 680rpx;
			}
		}

		.footer {
			width: 750rpx;
			height: 100rpx;
			background-color: #FFFFFF;
			margin: 40rpx auto;
		}
	}
</style>